MOOC Utils

Utils like auto assignment solver extension and course notice announcment notification for MOOC courses

Course management

Introduction#

Course discovery for Swayam and NPTEL: search, detail fetch, caching, and how course records feed subscriptions.

Project structure#

The course management system resides in the notice-reminders package and exposes:

  • A FastAPI backend with routers for courses, search, and announcements
  • A service layer that orchestrates scraping and persistence
  • Domain models for course and announcement data
  • Pydantic schemas for API serialization
  • Scrapers for Swayam/NPTEL course discovery and announcements

Core components#

  • Domain models define lightweight course and announcement entities used during scraping and processing.
  • ORM model persists normalized course records with indexing and timestamps.
  • Pydantic schemas define API response shapes for clients.
  • Services encapsulate business logic: course search and caching, announcement retrieval and deduplication, and integration with scrapers.
  • Scrapers handle HTTP requests and HTML parsing for Swayam and NPTEL.
  • Routers expose REST endpoints for listing/searching courses and retrieving course announcements.

Key responsibilities:

  • Course discovery: search courses via Swayam/NPTEL and normalize into ORM records
  • Data normalization: update existing records or insert new ones; maintain consistency
  • Caching: TTL-based filtering for recently updated courses
  • Announcement retrieval: fetch and de-duplicate announcements per course
  • API exposure: list, retrieve, search, and announcement listing endpoints

Architecture overview#

The system follows a layered architecture:

  • Presentation: FastAPI routers
  • Application: Service layer orchestrating scraping and persistence
  • Domain: Lightweight dataclasses for course and announcement
  • Infrastructure: Scrapers and ORM models

Detailed component analysis#

Course discovery and web scraping (swayam/NPTEL)#

  • The scraper targets Swayam’s course search endpoint and NPTEL’s announcements pages.
  • It parses course cards to extract title, instructor, institution, NC code, and course code.
  • It retrieves announcements for a given course code, handling alternate NPTEL domains.

Course service layer#

  • Provides search and cache orchestration, listing, lookup by code, and recent updates filtering.
  • Normalizes scraped data into ORM records, updating fields if changed and inserting new records otherwise.

Announcement service and data normalization#

  • Fetches announcements for a course and upserts them into the ORM.
  • Deduplicates by course + title + date; updates content if changed.

Data models and schemas#

  • Domain models: lightweight entities for course and announcement used during scraping and processing.
  • ORM model: persistent representation of a course with indexed code and timestamps.
  • Schemas: Pydantic models for API responses.

API endpoints and usage patterns#

  • List all courses
  • Get a course by code
  • Search courses (Swayam)
  • List announcements for a course

Course data structures and examples#

  • Domain Course: title, url, code, instructor, institute, nc_code
  • Domain Announcement: title, date, content
  • ORM Course: id, code (unique/indexed), title, url, instructor, institute, nc_code, created_at, updated_at
  • API CourseResponse: id, code, title, url, instructor, institute, nc_code, created_at, updated_at
  • API AnnouncementResponse: id, course_id, title, date, content, fetched_at

Usage pattern examples:

  • Search courses: call search endpoint with query; receive normalized CourseResponse[]
  • Retrieve announcements: call announcements endpoint for a course code; receive AnnouncementResponse[]

Dependency analysis#

The dependency graph shows how the API depends on routers, which depend on services resolved via dependency injection. Services depend on SwayamService, which depends on SwayamScraper. CourseService persists data via ORM; AnnouncementService persists announcements.

Performance considerations#

  • Caching strategy: Recently updated courses are filtered using a time-to-live window derived from settings, reducing repeated scraping for unchanged records.
  • Upsert efficiency: CourseService updates only changed fields and inserts new records, minimizing unnecessary writes.
  • Pagination: Current endpoints return full lists; adding pagination would reduce payload sizes and improve responsiveness for large datasets.
  • Concurrency: Scraping uses asynchronous HTTP client; ensure rate limiting and backoff to avoid overloading external sites.
  • Indexing: Course code is indexed for efficient lookups; consider additional indexes for frequently queried fields.

Troubleshooting guide#

  • Course not found: API returns 404 when retrieving a course by code that does not exist.
  • External site changes: Scrapers rely on HTML structure; if selectors change, parsing will fail. Review and update selectors in the scraper.
  • Network errors: Scrapers use an explicit User-Agent and follow redirects; ensure network connectivity and headers remain valid.
  • Announcement retrieval: Alternate NPTEL domain is handled automatically; if still failing, verify course code correctness and external availability.

Conclusion#

Search, upsert course rows, then subscribe. Cache hits should not hide stale titles forever; pick a TTL that matches term changes.

Appendices#

API endpoints summary#

  • GET /courses
  • Description: List all courses
  • Response: Array of CourseResponse
  • GET /courses/{course_code}
  • Description: Get a course by code
  • Response: CourseResponse
  • Error: 404 if not found
  • GET /search?q={query}
  • Description: Search courses by query
  • Response: Array of CourseResponse
  • GET /courses/{course_code}/announcements
  • Description: List announcements for a course
  • Response: Array of AnnouncementResponse